#include <iostream>
#include <chrono>
#include <random>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#define VNAME(name) (#name)
#define debug(x) {int debugx = x; std::cout << " (" << VNAME(x) << ": " << (debugx) << ")\n";}
#define F_(n) cout << fixed << setprecision(n)
using namespace std;
typedef long long LL;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
bool _linux_Flag;
/*static int _ = [](){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    return 0;
}();//*/
map<int, int> M;
int arr[N];
LL solve() {
    int n, flag = 0; LL sum = 0, res = 0; 
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> arr[i], sum += arr[i];
    //debug(sum);
    if (sum % n == 0 || ((flag = 1) && sum % n == n / 2 && n % 2 == 0)) sum = sum / n << 1 | flag;
    else return 0;
    for (int i = 1; i <= n; ++ i) M[arr[i]] ++;
    for (int i = 1; i <= n; ++ i) {
        M[arr[i]] --;
        res += M[sum - arr[i]];
    }
    M.clear();
    return res;
}
signed main() {
    #ifndef ONLINE_JUDGE
		_linux_Flag = false; //freopen("C:\\Users\\lenovo\\Desktop\\in.in", "r", stdin);
	#endif
    int t = 1;
    cin >> t;
    while (t --) {
        cout << solve() << endl;
        //debug(solve());
    }
    //system("pause");
    return 0;
}